package com.zld.smarket.controller;

import com.zld.smarket.pojo.GoodsType;
import com.zld.smarket.pojo.Shelves;
import com.zld.smarket.pojo.Storehouse;
import com.zld.smarket.result.ExceptionMsg;
import com.zld.smarket.result.ResponseData;
import com.zld.smarket.service.ShelvesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/shelves")
public class ShelvesController {
    @Autowired
    private ShelvesService shelvesService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ResponseData findList(Integer page, Integer limit) {
        return shelvesService.findList(page, limit);
    }

    @RequestMapping(value = "/del")
    public ResponseData delete(Long[] ids){
        Integer integer = shelvesService.deleteById(ids);
        return new ResponseData(ExceptionMsg.SUCCESS);
    }
    @RequestMapping(value = "/search",method = RequestMethod.GET)
    public ResponseData search(String s,Integer page, Integer limit){
        return  shelvesService.search(s,page,limit);
    }

    @RequestMapping(value = "/add")
    public ResponseData add(Shelves shelves) {
        Long i = shelves.getShelvesNo();
        if (shelvesService.selectbyno(i) > 0) {
            return new ResponseData(ExceptionMsg.ADDERROR);
        } else {
            Integer integer = shelvesService.addShelves(shelves);
            return new ResponseData(ExceptionMsg.SUCCESS);
        }
    }
    @RequestMapping(value = "/update")
    public ResponseData updateById(Shelves shelves){
        return shelvesService.updateById(shelves);
    }
    @RequestMapping("/getShelves")
    public List<Shelves> getShelves() {
        return shelvesService.selectAll();
    }
}
